
//--include file----
#pragma once
#include "CommonFile.h"
#include "CompressFile.h"
#include "CommonStruct.h"

#include "string.h"

CCompressFile::CCompressFile()
{
};


CCompressFile::~CCompressFile()
{
};

void CCompressFile::CompressFile()
{
	int tempStoreSizeFile = m_CommonFile.GetSizeFile("Data.txt") + 1;
	char* stringTemp = new char[tempStoreSizeFile];
	stringTemp = m_CommonFile.ReadDataFromFile("Data.txt");

	//-- using to count

	int countingDefferentByte = CountDefferentByte(stringTemp, tempStoreSizeFile);
	char* DataAfterCompress = new char[countingDefferentByte *2];
	memset(DataAfterCompress, 0, countingDefferentByte * 2);
	

	int tempCount = 0;
	char tempChar = stringTemp[0];

	int indexDataACp = 0;

	for (int i = 0; i < tempStoreSizeFile ; ++i){
		if (tempChar == stringTemp[i])
			tempCount++;
		if (tempChar != stringTemp[i]){

			DataAfterCompress[indexDataACp] = tempCount;
			DataAfterCompress[++indexDataACp] = tempChar;
			indexDataACp ++;

			tempChar = stringTemp[i];
			tempCount = 1;
		}
	}
	

	m_CommonFile.WriteDataToFile(DataAfterCompress, "DataCompress.txt");
};

